package com.woniu.airent.controller;

import com.github.pagehelper.PageInfo;
import com.woniu.airent.dto.SearchHouseDto;
import com.woniu.airent.service.impl.SearchHouseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * description:处理房源搜索的前后台数据交换
 *
 * @author AlenHx
 * @create 2020/9/29
 * @since 1.0.0
 */

@Controller
@RequestMapping("/search")
public class SearchHouseController {

    @Autowired
    SearchHouseServiceImpl searchHouseService;

    @ResponseBody
    @RequestMapping("/searchHouse")
    public PageInfo<SearchHouseDto> searchHouse(SearchHouseDto searchHouseDto,
                                                @RequestParam(value = "pageNum",defaultValue = "1")int pageNum,
                                                @RequestParam(value = "pageSize",defaultValue = "2")int pageSize,
                                                @RequestParam(value = "priceSort",defaultValue = "未定义")String priceSort,
                                                @RequestParam(value = "areaSort",defaultValue = "未定义")String areaSort){
        //1：价格升序  0：价格降序 2：啥也不是
        int priceState = 2;
        //1：面积升序  0：面积降序 2：啥也不是
        int areaState = 2;

        if (priceSort.equals("价格升序")){
            priceState = 1;
        }else if (priceSort.equals("价格降序")){
            priceState = 0;
        }

        if (areaSort.equals("面积升序")){
            areaState = 1;
        }else if (areaSort.equals("面积降序")){
            areaState = 0;
        }
        PageInfo<SearchHouseDto> pageInfo = searchHouseService.findHouse(searchHouseDto,pageNum,pageSize,priceState,areaState);
        return pageInfo;
    }

}
